package observer;

import java.util.LinkedList;
import java.util.Random;

import javax.swing.text.html.HTMLDocument.Iterator;

public class Senzor implements Subject {
	private LinkedList<Observer> obs = new LinkedList<Observer>();
	private int valCurenta = 0;
	
	//Adauga un Observator
	public void addObserver(Observer o){
		obs.add(o);
	}
	
	//Sterge un Observator
	public void removeObserver(Observer o ){
		obs.remove(o);
	}
	
	//Notifica Observerii
	public void notifyObserver() {
		Iterator i = obs.iterator();
		while (i.hasNext()) {
			Observer o = (Observer) i.next();
			o.upDate(this);
		}
	}
	
	//Genereaza un numar aleator
	public void generare() {
		Random serieRandom = new Random();
		valCurenta = serieRandom.nextInt(80);
		notifyObserver();
	}
	
	//Returneaza valoarea curenta
	public int getVal() {
		return valCurenta;
	}
}
